package com.ns.sbs.oauth.acc4auth.service;

import com.ns.core.project.MapperService;
import com.ns.core.utils.jwt.SystemUtil;
import com.ns.sbs.oauth.acc.entry.Account;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * 用户表 密码相关
 *
 * @author lw
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class AccPasswordServiceImpl implements IAccPasswordService {

    /**
     * 修改密码
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    @Override
    public int updatePassword(Long adminId, String password) {
        // 更改密码
        MapperService.publicMapper.updateColumnById(Account.TABLE_NAME, "password", SystemUtil.getPasswordMd5(adminId, password), adminId);
        if (Boolean.TRUE.equals(SystemUtil.config.getIsPw())) {
            // 明文密码
            MapperService.publicMapper.updateColumnById(Account.TABLE_NAME, "pw", password, adminId);
            return 2;
        }
        return 1;
    }


}
